package com.nuyoah.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.nuyoah.entity.Registration;
import com.nuyoah.mapper.RegistrationMapper;
import com.nuyoah.service.RegistrationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaoming
 * @since 2024-03-26
 */
@Service
public class RegistrationServiceImpl extends ServiceImpl<RegistrationMapper, Registration> implements RegistrationService {

    @Autowired
    private RegistrationMapper registrationMapper;
    @Override
    public boolean isRegistered(Long userId, Long activityId) {
        return registrationMapper.existsByUserAndActivity(userId, activityId);
    }

    @Override
    // RegistrationService.java
    public List<Registration> listByActivityId(Long activityId) {
        QueryWrapper<Registration> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("activity_id", activityId);
        return registrationMapper.selectList(queryWrapper);
    }

    @Override
    public Registration getByActivityIdAndUserId(Long id, Long userId) {
        return registrationMapper.selectOne(new QueryWrapper<Registration>().eq("activity_id", id).eq("user_id", userId));
    }

    @Override
    public List<Registration> getByActivityId(Long id) {
        return registrationMapper.getByActivityId(id);
    }

}
